package cj.primariaiquest.ws.endpoint;

	
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;

import cj.primariaiquest.schemas.ObjectFactory;
	import cj.primariaiquest.schemas.TicketRequest;
import cj.primariaiquest.schemas.TicketResponse;
import cj.primariaiquest.ws.exception.OutOfNumbersException;
import cj.primariaiquest.ws.service.TicketService;
	

	@Endpoint
	public class TicketEndpoint {

	    private final TicketService ticketService;
	    private final ObjectFactory objectFactory;

	    public TicketEndpoint(TicketService ticketService,
		    ObjectFactory objectFactory) {
		super();
		this.ticketService = ticketService;
		this.objectFactory = objectFactory;
	    }

	    @PayloadRoot(localPart = "TicketRequest", namespace = "http://www.primariaIquest.cj/schemas")
	public TicketResponse getTicketNumber(TicketRequest ticketRequest)
			throws OutOfNumbersException {
		TicketResponse ticketResponse = objectFactory.createTicketResponse();
		    ticketResponse.setNumber(ticketService.getNumber(ticketRequest
			    .getDepartment()));

		return ticketResponse;
	    }
	}
	
